import React from "react";
import classNames from "classnames";
import PropTypes from "prop-types";

import "./Timeline.less";
import TimelineItem from "./TimelineItem";

export default class Timeline extends React.Component {
  static Item = TimelineItem;
  static defaultProps = {
    prefixCls: "ant-timeline"
  };

  render() {
    const { prefixCls, children, className, ...restProps } = this.props;
    const classString = classNames(prefixCls, className);

    const items = React.Children.map(children, (ele, idx) =>
      React.cloneElement(ele, {
        last: idx === children.length - 1
      })
    );
    return (
      <ul {...restProps} className={classString}>
        {items}
      </ul>
    );
  }
}
Timeline.propTypes = {
  prefixCls: PropTypes.string,
  className: PropTypes.string,
  children: PropTypes.any
};
